package note.pojo;

/**
 * @program: LeetCodePractice
 * @description: 实现Comparable接口的日期类，测试排序
 * @author: WongKee
 * @create: 2020-08-27 08:39
 **/
public class Date implements  Comparable<Date>{
    private final int day;
    private final int month;
    private final int year;

    public Date(int d,int m,int y){
        day=d;
        month=m;
        year=y;
    }

    public int getDay() {
        return day;
    }

    public int getMonth() {
        return month;
    }

    public int getYear() {
        return year;
    }


    @Override
    public int compareTo(Date date) {
        if(this.year>date.year) return +1;
        if(this.year<date.year) return -1;

        if(this.month>date.month) return +1;
        if(this.month<date.month)  return -1;

        if(this.day>date.day) return +1;
        if(this.day<date.day) return -1;

        return 0;
    }

    @Override
    public String toString() {
        return "Date{" +
                "day=" + day +
                ", month=" + month +
                ", year=" + year +
                '}';
    }
}
